<?php
namespace app\api\model;
use plugin\filter;
use think\Model;

/*基类模型*/
class Mail extends Model
{
    private $table_name = 'mail';
    public function defaultParam($args)
    {
        $data = [
            'title' => '',
            'description' => '',
            'content'   => '',
            'phone'     => '',
        ];

        return array_merge($data,$args);
    }
    public function add($input)
    {
        $input = $this->defaultParam($input);
        if(empty($input['title'])
            || empty($input['description'])
            || empty($input['content'])
            || empty($input['phone']))
        {
            return ['error' => 1 , 'msg' => "参数错误"];
        }
        $input['phone'] = trim($input['phone']);
        if(!filter::regex_true($input['phone'],'tel'))
        {
            return ['error'=>1, 'msg' => '手机号码错误'];
        }
        $input = resetArr($input,['title','description','content','phone']);
        $input['add_time'] = time();
        db($this->table_name)->insert($input);
        return ['error'=>0,'msg'=>'站内信发送成功，管理员会尽快与您联系'];
    }
}